package com.yuelao.thread.demo;

/**
 * 测试wait方法
 * Created by fengliye on 2017/10/6.
 */
public class ThreadWait {
    public static void main(String[] args) {
        Hello hello = new Hello();
        Thread t1 = new Thread(() -> {
            try {
                synchronized (hello) {
                    System.out.println("线程中断5秒钟");
                    hello.wait(5000);
                    hello.say();
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }, "t1");
        t1.start();

        Thread t2 = new Thread(() -> {
            try {
                synchronized (hello) {
                    Thread.sleep(3000);
                    System.out.println("唤醒t1线程");
                    hello.notify();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "t2");
        //t2.start();
    }

    static class Hello {
        void say() {
            System.out.println("hello");
        }
    }
}
